#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int left = 0, right = 0, ret = 0, n = s.size();
    int hash[26] = { 0 };
    int count = 0;

    while (right < n)
    {
        if (hash[s[right] - 'a']++ == 0) count++;
        while (count > 2)
        {
            if (hash[s[left++] - 'a']-- == 1) count--;
        }
        ret = max(ret, right - left + 1);
        right++;
    }
    cout << ret << endl;
    return 0;
}